package com.modules.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.beanutils.ConversionException;
/**
 * @author kgdoqi extends saiyo
 *
 */
public class DateHelper {
	
	public  Calendar cal;
	private Integer year, day, month, hour, minute,second;
	
	/**
	 * 
	 */
	public  DateHelper(){
		cal = Calendar.getInstance();
		year = Integer.valueOf(cal.get(cal.YEAR));
		day = Integer.valueOf(cal.get(cal.DAY_OF_MONTH));
		month = Integer.valueOf(cal.get(cal.MONTH) + 1);
		hour = Integer.valueOf(cal.get(cal.HOUR_OF_DAY));
		minute = Integer.valueOf(cal.get(cal.MINUTE));
		second = Integer.valueOf(cal.get(cal.SECOND));
	}
	
	//
	public String getCurrentDate(String language) {

		if (language.equals("EN")) {
			String currentDateEN = month + "-" + day + "-" + year + " " + hour + ":" + minute;
			return currentDateEN;
		}
		String currentDateCN = year + "年" + month + "月" + day + "日" + hour + ":" + minute;
		return currentDateCN;
	}
	
	
	public String getCurrentDate()
	{
		String currentDateEN = year+"-"+ month + "-" + day;
			return currentDateEN;
	}

	// 
	public String getRandomNum() {
		String strTime = year.toString() + month.toString() + day.toString()
				+ hour.toString() + minute.toString();
		String strRan = strTime
				+ String.valueOf(Math.round(Math.random() * 8999 + 1000));
		return strRan;
	}
	public String getCurrentDateTimeNum(){
		String currentDateEN = year+""+ month + "" + day+""+hour+""+minute+"";
		return currentDateEN;
	}
	
	public   int compareDate(String strDate1,String strDate2){
	    	Date date1=convertToDate(strDate1);
	    	Date date2=convertToDate(strDate2);
	    	return date1.compareTo(date2);
	    }
	
    public  Date convertToDate(String strDate) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date=null;
        if (strDate!=null&&!"".equals(strDate)) {
        	try{
             date = df.parse((String) strDate);
            } catch (Exception pe) {
                pe.printStackTrace();
                throw new ConversionException("Error converting String to Date");
            }
        }
        return date;
    }
   
}
